import {
	readonly,
	ref
} from 'vue';
import {
	getUserMember
} from '@/config/api/user';
import {
	useLoginStore
} from '@/store/login';
const useMember = () => {
	const store = useLoginStore()
	const memberInfo = ref({});
	const memberList = ref([])
	const memberCard = readonly([{
			level: 0,
			text: '普通会员',
			style: {
				background: 'linear-gradient(135deg, #EFEFEF 0%, #A7A7A7 100%)',
				color: '#676767',
				activeColor: '#676767',
				inactiveColor: '#EFEFEF'
			}
		},
		{
			level: 1,
			text: '青铜会员',
			style: {
				background: 'linear-gradient(135deg, #F1D9C5 0%, #EBCCB2 100%)',
				color: '#70401D',
				activeColor: '#70401D',
				inactiveColor: '#EBCCB2'
			}
		},
		{
			level: 2,
			text: '白银会员',
			style: {
				background: 'linear-gradient(135deg, #E9EFFF 0%, #E2EAF1 100%)',
				color: '#585B66',
				activeColor: '#585B66',
				inactiveColor: '#E2EAF1'
			}
		},
		{
			level: 3,
			text: '黄金会员',
			style: {
				background: 'linear-gradient(135deg, #FDF8D5 0%, #F5E5B7 100%)',
				color: '#754625',
				activeColor: '#754625',
				inactiveColor: '#F5E5B7'
			}
		},
		{
			level: 4,
			text: '钻石会员',
			style: {
				background: 'linear-gradient(135deg, #D2E8FF 0%, #A1C2F3 100%)',
				color: '#264167',
				activeColor: '#264167',
				inactiveColor: '#A1C2F3'
			}
		}
	]);
	const getUserMemberInfo = async () => {
		try {
			const res = await getUserMember();
			if (res.code == 200) {
				console.log(res);
				const info = res.data;
				const userLevelList = res.data.userLevelList;
				const userLevel = res.data.userLevel;
				info.next = userLevelList.find((e) => e.level === userLevel + 1) || userLevelList[
					userLevelList.length - 1];
				const card = memberCard.find((e) => e.level === userLevel);
				const nextCard = memberCard.find((e) => e.level === info.next.level);
				info.next.text = nextCard.text;
				info.next.equity = info.next.userEquityList.length;
				memberInfo.value = Object.assign(info, card);
				store.memberInfo = memberInfo.value;
				memberList.value = userLevelList.map((e) => {
					const card = memberCard.find((c) => c.level === e.level);
					return Object.assign(e, card);
				});
				store.memberList = memberList.value;
			}
		} catch (error) {
			//TODO handle the exception
		}
	};
	return {
		getUserMemberInfo,
		memberInfo,
		memberList
	};
}
export default useMember;